#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
This is a handler for lighttpd+fastcgi
This file has to be in the PYTHONPATH
Put something like this in the lighttpd.conf file:

server.port = 8000
server.bind = "127.0.0.1"
server.event-handler = "freebsd-kqueue"

server.document-root = "/path/to/web2py/"
server.error-handler-404 = "/web2py.fcgi" # Forwards all requests to web2py
server.dir-listing = "disable" # Required, else / will just show a directory listing
server.errorlog = "/tmp/error.log"
server.modules += ( "mod_fastcgi" ) # The fastcgi module is required, of course, for fastcgi to work ;)
fastcgi.server = ( ".fcgi" => 
	("localhost" => (
		"min-procs" => 1, 
		"socket" => "/tmp/web2py.sock" )
	)
	)
"""

import sys
import os

import gluon.main
import gluon.contrib.gateways.fcgi as fcgi
from gluon.contrib.wsgihooks import ExecuteOnCompletion2, callback

# Append the file path in python path
path = os.path.dirname(os.path.abspath(__file__))
if not path in sys.path:
    sys.path.append(path)
os.chdir(path)

# Choose one of the ways below to define the application
# application = ExecuteOnCompletion2(gluon.main.wsgibase, callback)

application=gluon.main.wsgibase
# # or
# application=gluon.main.wsgibase_with_logging

fcgi.WSGIServer(application).run()
